<?php
/*
	[Phpup.Net!] (C)2009-2011 Phpup.net.
	This is NOT a freeware, use is subject to license terms

	$Id: session.class.php 2010-08-24 10:42 $
*/

if(!defined('IN_PHPUP')) {
	exit('Access Denied');
}
function ssetcookie($var, $value, $life = 0, $httponly = FALSE) {
	$life = $life? $GLOBALS['timestamp'] + $life : 0;
	$secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
	
	if(PHP_VERSION < '5.2.0') {
		setcookie($GLOBALS['cookiepre'].$var, $value, $life, $GLOBALS['cookiepath'], $GLOBALS['cookiedomain'], $secure);
	} else {
		setcookie($GLOBALS['cookiepre'].$var, $value, $life, $GLOBALS['cookiepath'], $GLOBALS['cookiedomain'], $secure, $httponly);
	}
}

function getcookie() {

	$supe_uid = 0;
	$supe_username= 'Guest';
	$member = array(
		'uid' => 0,
		'groupid' => 2,
		'username' => 'Guest',
		'password' => ''
	);
	
	$cookie = $_COOKIE[$GLOBALS['cookiepre'].'auth'];


	if($cookie) {
		@list($password, $uid) = explode("\t", authcode($cookie, 'DECODE'));
		
		$uid = intval($uid);
		
		$password = global_addslashes($password);
		$cinfo['uid'] = $uid;
		$member=uc_user_login($uid, $password,1);
		if($member) {
			$cinfo['username'] = global_addslashes($member[1]);
			$cinfo['email'] = global_addslashes($member[3]);
		} else {
			$cinfo['uid'] = 0;
		}
	}
	if(empty($cinfo['uid'])) sclearcookie();	
	return $cinfo;
}

function sclearcookie() {

	ssetcookie('sid', '', -86400 * 365);
	ssetcookie('auth', '', -86400 * 365);
	ssetcookie('sauth', '', -86400 * 365);
}